;;;; config company-go

(require 'gotest)

;; set up go-run with all go files in path
(defun go-run-with-all-file ()
  (interactive)
  (compile (go-test--go-run-get-program
            (s-concat (file-name-directory (buffer-file-name)) "*.go")
            )))

;; build current package
(defun go-install ()
  (interactive)
  (cd (file-name-directory (buffer-file-name)))
  (shell-command "go install"))

(require 'company)
(require 'company-go)
(define-key go-mode-map (kbd "C-c C-c") 'company-go)
;;(define-key go-mode-map (kbd "C-c C-e") 'go-run)
(define-key go-mode-map (kbd "C-c C-e") 'go-run-with-all-file)
(setq company-tooltip-limit 20)
(setq company-idle-delay .3)
(setq company-echo-delay 0)
(setq company-begin-commands '(self-insert-command))

;; config auto-complete
;; (require 'go-autocomplete)
;; (require 'auto-complete-config)
;; (ac-config-default)

; 
(add-hook 'go-mode-hook
          (lambda ()
            (add-hook 'before-save-hook 'gofmt-before-save)
            (add-hook 'after-save-hook 'go-install)
;;            (local-set-key (kbd "RET") 'newline-and-indent)
            (setq tab-width 4)
            (setq indent-tabs-mode 1)))

(add-hook 'go-mode-hook 'electric-pair-local-mode)
(add-hook 'go-mode-hook 'electric-indent-mode)

(exec-path-from-shell-initialize)
(exec-path-from-shell-copy-env "GOPATH")
